﻿-- =============================================
-- Script Template
-- =============================================
SELECT     DATEPART(hour, t.DateCreated) AS hour, SUM(t.RealIn) AS RealIn
FROM         DB01.RetailStat.dbo.Shops AS s INNER JOIN
                      DB01.RetailStat.dbo.Entries AS e ON e.ShopID = s.ID INNER JOIN
                      DB01.RetailStat.dbo.Sensors AS n ON n.EntryID = e.ID INNER JOIN
                      DB01.RetailStat.dbo.Traffic AS t ON t.SensorID = n.ID
WHERE     (YEAR(t.DateCreated) = 2011) AND (MONTH(t.DateCreated) = 7) AND (DAY(t.DateCreated) = 11) AND (s.Name = 'Балашиха')
GROUP BY s.Name, DATEPART(hour, t.DateCreated)
